home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8150 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.3 KB  |  103 lines

  1. Path: service-2.agate.net!usenet
  2. From: andle@biode.com (Jeffrey C. Andle)
  3. Newsgroups: comp.lang.c++
  4. Subject: Bounds checker says this is a leak.  Is it?
  5. Date: 15 Feb 1996 04:50:42 GMT
  6. Organization: Biode, Inc.
  7. Message-ID: <4fue32$k77@service-2.agate.net>
  8. NNTP-Posting-Host: biode.sdi.agate.net
  9. Mime-Version: 1.0
  10. X-Newsreader: WinVN 0.93.11
  11.  
  12. First, I'm running VC4.0 in NT3.51 with so much virtual ram that I
  13. don't see leaks that Bounds checker says are there.  So, is this a leak?
  14. I have a valid destructor which deletes each cELEMENT in the list.
  15. It is called & I can trace through it.  I suspect that bounds checker
  16. is being paranoid.  I create an element using new, as shown in the routine
  17.  
  18. bAddTopItem(DataIn);
  19.  
  20. I added the code to initialize NULL and close out with NULL in pNew
  21. just to see if Bounds checker still had the same opinion.  It did.
  22. Since the new cELEMENT is on the list and is ultimately destroyed,
  23. If there really is a leak, I assume it has to do with the use of 
  24. references in the constructor... (?)
  25.  
  26. Any help would be vastly appreciated.  This templated code is the core
  27. of my data linked lists, my message processing jump table and my 
  28. child windows lists.  If there really are as many leaks as Bounds checker 
  29. says, I would thing I'd notice it...
  30.  
  31. Also, how do I reliably test for memory losses in NT?
  32. e-mail to andle@agate.net please.
  33.  
  34.  
  35. ************************************************************* Add Element creates an element on the list 
  36. ************************************************************* containing the data
  37. // ==============================================================
  38. // Add element to top of list                
  39. // Pre: DataIn                
  40. template<class ITEM,class KEY> BOOL cLINKEDLIST<ITEM,KEY>::bAddTopItem        (ITEM DataIn)
  41. {
  42. cELEMENT<ITEM>*    pNew = NULL;
  43. BOOL        bSuccess = FALSE;
  44.  
  45.     pNew = new cELEMENT<ITEM> (DataIn, NULL, pTop);    // ***********<<<<<<<<<
  46.     if ((BOOL) pNew)
  47.     {
  48.         // add the new element (splice pointers)
  49.         if (!bEmptyList()) 
  50.         {
  51.             pTop->pSetPrev (pNew);
  52.         }
  53.         else
  54.         {
  55.             // Adding first element to empty list
  56.             pCur = pNew;
  57.             pBot = pNew;
  58.         }
  59.  
  60.         pTop = pNew;
  61.         bSuccess = TRUE;
  62.     }
  63.     // attempt to convince bounds checker that pNew is elsewhere now...
  64.     pNew = NULL;
  65.     return bSuccess;
  66. };
  67. // post:  properly spliced new element is in the list
  68. //          returns TRUE on success. pTop = pNew    
  69.  
  70.  
  71. ************************************************************ Element constructor copies DataIn
  72. template<class ITEM> class cELEMENT 
  73. {
  74. protected:
  75.         cELEMENT<ITEM>*    pNext;
  76.         cELEMENT<ITEM>*    pPrev;
  77.         ITEM        Item;
  78. public:
  79.     //===========================================================================
  80.     // Constructor
  81.     //
  82.     // Comments : This is set up to accept a multitude of arguments.
  83.     // if a class is used in the template, copy the class.  
  84.     // If a pointer to a class is used, copy the pointer.
  85.     // In either case, copy the pointers to next & prev.
  86.  
  87.     inline cELEMENT (ITEM& ItemIn, cELEMENT* pPrevIn = NULL, cELEMENT* pNextIn = NULL)
  88.     {
  89.     // if a class is used in the template, copy the class.  
  90.     // If a pointer to a class is used, copy the pointer.
  91.         Item = ItemIn;
  92.  
  93.     // In either case, copy the pointers to next & prev.
  94.         pPrev = pPrevIn;
  95.         pNext = pNextIn;
  96.     };
  97.     // POST : an instance of element has been created &&
  98.     //===========================================================================
  99.  
  100. // other stuff:
  101. };
  102.  
  103.